Number.prototype.twoDigits = function () {
    return ("0" + this).slice(-2);
}

// 根据毫秒数决定是否显示冒号
function getColon(milliseconds) {
    return (milliseconds < 500) ? ":" : '<span class="invisible">:</span>';
}

function refreshTime() {
    const time = new Date(Date.now() + 500);
    const hours = time.getHours().twoDigits();
    const minutes = time.getMinutes().twoDigits();
    const milliseconds = time.getMilliseconds();

    postMessage(hours + getColon(milliseconds) + minutes);
    setTimeout("refreshTime()", 500);
}

refreshTime();